/*
 * DBTreeTab.java
 *
 * Created on May 17, 2006, 11:39 PM
 *            2, February 2010: The tree nodes names, useds to identify mouse clicks into mouseRelesase method, were changed from hard code, to the use of getName class Method.
 *                              This class and ProjectTreeTab are now on aligned, in order to allow to aply to them Patterns.
 * 
 * 21, March 2012. In order to support the Factory design of the DBtree, the method
 *                 getClassPopupOption was modified. Now the method gets the superclass
 *                 node's name, aand allows it to discard the implementation of the node
 *                 for a particular DB engine.
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package portfolio.dbHost;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import portfolio.dbHost.dataBases.DBase;
import portfolio.dbHost.dataBases.dbTable.Table;
import portfolio.dbHost.dataBases.dbTable.tblColumn.Column;
import portfolio.mainScreen;

/**
 *
 * @author ACA
 */
public class DBTreeTab extends TreeTab
{
    JPanel jTreePanel = null;
    /**
     * Creates a new instance of DBTreeTab
     */
    public DBTreeTab (JPanel jTreePanelParam) throws Exception
    {
        jTreePanel = jTreePanelParam;
        if (jTreePanel == null)
            throw new Exception ("No jTreePanel provided.");

        jTreePanel.setLayout(new BorderLayout ());
    }
    /**
     * 
     */
    public void initComponents (Host dbasesHostParam)
    {
         try {
            treeObject = dbasesHostParam;
            if (treeObject == null)
                throw new Exception ("No rootHost provided.");

            mainFrame = this.getMainScreen (treeObject);

            DefaultMutableTreeNode root = ((Host) treeObject).processTreeHierarchy ();

            visibleTree = new JTree(root);
            visibleTree.addMouseListener(this);

            JScrollPane scrollTree = new JScrollPane ();
            scrollTree.getViewport ().add (visibleTree);

            jTreePanel.add(scrollTree, BorderLayout.CENTER);
        } catch (Exception ex) {
            mainFrame.displayMessage("DBTreeTab.DBTreeTab 142", ex.toString());
        }            
    } /* end constructor DBTreeTab */
    /**
     * 
     */
    mainScreen getMainScreen (Object treeObject)
    {
        return ((Host) treeObject).getMainScreen ();
    }
    /**
     * 
     */
    DefaultMutableTreeNode getMutableTreeNode (Object treeObject)
    {
        return ((Host) treeObject).processTreeHierarchy();
    }
    /**
     * 
     */
     Object getTreeObject (Object [] objectPath)
      {
          return ((Host) treeObject).getTreeObject (objectPath);
      }
    /**
     * 
     */
    void getClassPopupOption(Object oPopup, int iXPos, int iYPos) 
    {
        try {
            String sClassName = oPopup.getClass().getSuperclass().getName();
            
            if        (sClassName.equals (Host.class.getName())) {
                ((Host)   oPopup).getPopupOptions(visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (DBase.class.getName())) {
                ((DBase)  oPopup).getPopupOptions(visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (Table.class.getName())) {
                ((Table)  oPopup).getPopupOptions(visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (Column.class.getName())) {
                ((Column) oPopup).getPopupOptions(visibleTree, iXPos, iYPos);
            } else {
                mainFrame.displayMessage("DBTreeTab.mouseReleased 90", "error at jDBaseTree.");
            }
        } catch (Exception ex) {
/*0j0*/     mainFrame.displayMessage("DBTreeTab.mouseReleased 93", ex.toString());
        }
    }
} /* end class DBTreeTab */
